<template>
  <treeselect v-model="deptId" :options="deptOptions" :show-count="true"  placeholder="请选择归属部门" />
</template>

<script>

import {deptTreeSelect} from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  components: {Treeselect},
  props: {
    value: {
      required: true
    },
  },
  data() {
    return {
      // 部门树选项
      deptOptions: undefined,
      deptId:this.value
    };
  },
  watch: {
    value(newVal) {
      // 当父组件更新 prop 时，同步更新内部的 data 属性
      this.deptId = newVal;
    },
    deptId(newVal) {
      // 当内部选中的值变化时，通知父组件更新
      this.$emit('input', newVal);
    }
  },
  created() {
    this.getDeptTree()
  },
  methods: {
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
  }
};
</script>




